package com.sjq.supplier.controller;


import com.sjq.supplier.util.Result;
import lombok.extern.slf4j.Slf4j;
import com.sjq.supplier.entity.Evaluation;
import com.sjq.supplier.service.EvaluationService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Evaluation)表控制层
 *
 * @author makejava
 * @since 2024-01-02 14:54:50
 */
@Slf4j
@RestController
@RequestMapping("evaluation")
public class EvaluationController {
    /**
     * 服务对象
     */
    @Resource
    private EvaluationService evaluationService;

    /**
     * 分页查询所有数据
     *
     * @param evaluation 查询实体
     * @return 所有数据
     */
    @GetMapping("selectAll")
    public Result selectAll(Evaluation evaluation, Integer limit, Integer page) {
        if (limit == null || page == null) {
            return Result.failure("limit和page不能为空");
        }
        return evaluationService.selectAll(evaluation,limit,page);
    }

    /**
     * 新增数据
     *
     * @param evaluation 实体对象
     * @return 新增结果
     */
    @PostMapping("add")
    @Transactional(rollbackFor = Exception.class)
    public Result insert(Evaluation evaluation) {
        //判断evaluation是否为空
        if (evaluation== null) {
            return Result.failure("参数为空");
        }

        evaluation.setIsvalid(1);
        evaluation.setTime(new java.util.Date());

        if (evaluationService.save(evaluation)){
            return Result.success("评价成功");
        }
        return Result.failure("评价失败");
    }


}

